package com.baijiaoxi.common.model;

import com.baijiaoxi.common.model.base.CommonError;
import com.baijiaoxi.common.model.base.CoreException;
import lombok.Data;

import java.util.Arrays;
import java.util.List;

@Data
public class Email {
    private List<String> targetList;
    private String target;
    private String subject;
    private String html;

    public Email(String target, String subject, String html) {
        this.subject = subject;
        this.html = html;
        if(target==null||target.isEmpty())
            throw CoreException.create(CommonError.objectIsNull, "目标邮箱");
        this.target = target.replace(";", ",");
        if (!target.contains("@"))
            throw CoreException.create(CommonError.illegalEmailAddress, target);
        if(target.contains(",")){
            String []arr=target.split(",");
            targetList= Arrays.asList(arr);
        }
    }

    public Email() {
    }
}
